//订单确认页面
var basePage = require('../../../common/BasePage');
Page({
    behaviors: [basePage],
    data: {
        
		wuliu:[],
		pack_list:[],
		selectIndex:0,
		CompanyIndex:0,
		shippingIndex:0
		
    },
    onLoad: function (option) {
		console.log("option",option)
        this.setData({
			selectIndex:option.selectIndex,
			CompanyIndex:option.CompanyIndex,
			shippingIndex:option.shippingIndex
		})
		var that=this
		const eventChannel = this.getOpenerEventChannel();
		eventChannel.on('wuliu', function (data) {
				var wuliu=data.wuliu
				// var pack_list=wuliu[0].pack_list
		    that.setData({
		        // pack_list:pack_list,
						wuliu:wuliu
		    })
		
		})
    },
    
	
	
	/* 选择物流 */
	clickwuliu(e){
		this.setData({
			selectIndex:e.currentTarget.dataset.index,
			CompanyIndex:-1,
			shippingIndex:0
		})
	},
	clickshipping(e){
        var groupInfo = this.data.wuliu[this.data.selectIndex].shipping_list[e.currentTarget.dataset.key].group_list[e.currentTarget.dataset.index]
        if(groupInfo.is_stop==1){
            wx.showModal({
              title: '当前物流公司已停用',
              content: groupInfo.stop_cause,
              showCancel:false,
              complete: (res) => {
                
              }
            })
            return;
        }
		this.setData({
			CompanyIndex:e.currentTarget.dataset.index,
			shippingIndex:e.currentTarget.dataset.key
		})
		
	},
	submitShipping: function (e) { 
	  console.log('submitShipping', e);
      var that=this
      if(that.data.CompanyIndex==-1){
          wx.showToast({
            title: '请选择物流公司',
            icon:"none"
          })
          return;
      }
	  const eventChannel = this.getOpenerEventChannel();
	  eventChannel.emit('change_selectIndex', {
	    selectIndex: that.data.selectIndex,
		CompanyIndex:that.data.CompanyIndex,
		shippingIndex:that.data.shippingIndex
	  });
	  wx.navigateBack({
	    delta: 1,
	  })
	},
})